package main

import (
	"github.com/gin-gonic/gin"
	"github.com/spf13/viper"
	"learningProject/vueGoProject/common"
	"learningProject/vueGoProject/routers"
	"os"
)

func main() {
	InitConfig()
	err := common.InitMySQL()
	if err != nil {
		panic(err)
	}
	defer common.DB.Close()

	r := gin.Default()
	r = routers.CollectRouter(r)
	port := viper.GetString("server.port")
	panic(r.Run(":" + port))
}

func InitConfig() {
	workDir, _ := os.Getwd()
	viper.SetConfigName("application")
	viper.SetConfigType("yml")
	viper.AddConfigPath(workDir + "/config")
	if err := viper.ReadInConfig(); err != nil {
		panic(err)
	}

}
